<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/background/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/background/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/background/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/background/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/background/lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/background/js/xadmin.js"></script>
</head>
<body>
<div class="x-body">
    <form id="rrr" class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>动物编号
            </label>
            <div class="layui-input-inline">
                <input type="text" name="anId" value="${animal.anId}" required readonly=“readonly” lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>动物类型
            </label>
            <div class="layui-input-inline">
                <select id="classFlag" name="anTypeId" class="species">
                    <c:forEach items="${allAnimalType}" var="y" varStatus="row">
                        <option value="${y.tyId}" <c:if test="${y.tyId == animal.anTypeId}">selected</c:if>>${y.tyName}</option>
                    </c:forEach>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>动物名字
            </label>
            <div class="layui-input-inline">
                <input type="text" id="className" name="anName" value="${animal.anName}" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>动物年龄
            </label>
            <div class="layui-input-inline">
                <input type="text" name="anAge" value="${animal.anAge}" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>性格描述
            </label>
            <div class="layui-input-inline">
                <input type="text" name="anFormation" value="${animal.anFormation}" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>照片
            </label>
            <div class="layui-input-inline">
                <img src="${animal.anPicture}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" type="button" lay-filter="add" onclick="modifyAnimal()" lay-submit="">
                修改
            </button>
        </div>
    </form>
</div>
<script type="text/javascript">
    function modifyAnimal(){
        $ = layui.jquery;
        var layer = layui.layer;
        var formData=new FormData($("#rrr")[0]);
        //监听提交
        $.ajax({
            type:'POST',
            url:'modifyAnimal',
            data:formData,
            async: false,
            contentType: false,
            processData: false,
            //等待返回值
            success:function(result){
                if(result=="SUCCESS"){
                    layer.alert("添加成功", {icon: 6},function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                        //刷新我的 双亲页面 classobjlist.jsp
                        window.parent.location.reload();
                    });
                }
                else{
                    layer.alert(result,{title:"添加失败"});
                }
            }
        });
        return false;
    }

</script>
</body>
</html>